package jianzhi_offer;

import java.util.Arrays;

public class _44_扑克牌顺子 {
    public static void main(String[] args) {
        _44_扑克牌顺子 test = new _44_扑克牌顺子();
        System.out.println(test.isContinuous(new int[]{0,1,3,6,0}));
    }
    public boolean isContinuous(int [] numbers) {
        if(numbers == null || numbers.length == 0) return false;
        Arrays.sort(numbers);
        int index = -1;
        while(numbers[index+1] == 0) ++index;//有几张王
        int pre = numbers[index+1];//这张牌认为是顺子的开始
        index++;
        for(int i=index+1;i<numbers.length;++i){
            if(numbers[i] == pre) return false;//有重复的牌
            if(numbers[i] != pre+1){
                if(index == 0) return false;//没有花牌
                else{
                    index--;
                    pre++;
                    --i;//这张牌没有消耗
                }
            }else{
                pre++;
            }
        }
        return true;
    }
}
